package com.cxkj.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.cxkj.dto.Gettable;
import com.cxkj.service.GettableService;

@Controller
@RequestMapping("/getTable")
public class GettableController {
	
	@Autowired
	private GettableService gettableService;
	
	/**
	 * 转至单据领取页面
	 * @return
	 */
	@RequestMapping("/addGet")
	public String addGet(){
		
		return "receive";
	}
	/**
	 * 新增单据领取信息
	 * @param gettable
	 * @param request
	 * @return
	 */
	@RequestMapping("/insertGet")
	public String insertGet(Gettable gettable,HttpServletRequest request,MultipartFile file){
		
		gettableService.insertGet(gettable,request,file);
		
		return "redirect:/getTable/showGet?pageNow=1";
	}
	/**
	 * 领取册号重复检测
	 * @param gettable
	 * @param response
	 * @return
	 */
	@RequestMapping("/getTest")
	@ResponseBody
	public Map<String,Object> getTest(Gettable gettable,HttpServletResponse response){
		response.setCharacterEncoding("UTF-8");
		List<Gettable> getList=gettableService.getTest(gettable);
		Map<String, Object> result=new HashMap<String, Object>();
		if(getList.size()==0){
			result.put("result", "0");
		}else{
			result.put("result", "1");
		}
		return result;
	}
	
	/**
	 * 分页查询领取数据
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/showGet")
	public String showGet(HttpServletRequest request,Model model){
		gettableService.showGet(request, model);
		return "receive-summary";
	}
	
	
	

}
